# 主机系统别名配置
# 使用方法: source bashrc_host.sh 或添加到 ~/.bashrc

# Docker 相关
alias dr='sudo docker load -i my-ubuntu-ros2_v3.tar'
alias dps='sudo docker ps'
alias dpsa='sudo docker ps -a'
dex() {
    if [ -z "$1" ]; then
        if [ -z "$DOCKER_ID" ]; then
            echo "错误: 请先设置 DOCKER_ID 环境变量或提供容器ID"
            echo "使用方法: export DOCKER_ID='容器ID' 或 dex <容器ID>"
            return 1
        fi
        docker exec -it "$DOCKER_ID" /bin/bash
    else
        docker exec -it "$1" /bin/bash
    fi
}
dcm() {
    if [ -z "$1" ] || [ -z "$2" ]; then
        echo "使用方法: dcm <容器ID> <新镜像名:标签>"
        echo "示例: dcm abc123 my-ubuntu-ros2:v4"
        return 1
    fi
    sudo docker commit "$1" "$2"
    echo "容器已保存为新镜像: $2"
}
drun() {
    if [ -z "$1" ]; then
        echo "please provide id or name of docker"
        return 1
    fi
    CONTAINER_ID=""
    if docker inspect "$1" >/dev/null 2>&1; then
        CONTAINER_ID="$1"
    else
        CONTAINER_ID=$(docker ps -a --filter "ancestor=$1" --format "{{.ID}}" | head -1)
        if [ -z "$CONTAINER_ID" ]; then
            echo "错误: 容器或镜像 '$1' 不存在"
            echo ""
            echo "当前所有容器："
            docker ps -a --format "table {{.Names}}\t{{.ID}}\t{{.Image}}\t{{.Status}}"
            return 1
        fi
    fi
    docker exec -it "$CONTAINER_ID" /bin/bash
}
drunp() {
    if [ -z "$1" ]; then
        echo "使用方法: drunp <镜像名:标签>"
        echo "示例: drunp my-ubuntu-ros2:v4"
        return 1
    fi
    CONTAINER_ID=$(sudo docker run -d --privileged --net=host --gpus all -v /dev:/dev -v /home/agilex/Downloads/RoboOrchardLab:/RoboOrchardLab "$1" /bin/bash -c "while true; do sleep 3600; done")
    echo "容器已启动，ID: $CONTAINER_ID"
    export DOCKER_ID="$CONTAINER_ID"
    echo "DOCKER_ID 已自动设置为: $DOCKER_ID"
    echo "使用 'dex' 进入容器"
}
dstp() {
    if [ -z "$1" ]; then
        if [ -z "$DOCKER_ID" ]; then
            echo "错误: 请先设置 DOCKER_ID 环境变量或提供容器ID"
            echo "使用方法: export DOCKER_ID='容器ID' 或 dstp <容器ID>"
            return 1
        fi
        sudo docker stop "$DOCKER_ID"
        echo "容器已停止: $DOCKER_ID"
    else
        sudo docker stop "$1"
        echo "容器已停止: $1"
    fi
}
drm() {
    if [ -z "$1" ]; then
        if [ -z "$DOCKER_ID" ]; then
            echo "错误: 请先设置 DOCKER_ID 环境变量或提供容器ID"
            echo "使用方法: export DOCKER_ID='容器ID' 或 drm <容器ID>"
            return 1
        fi
        sudo docker rm "$DOCKER_ID"
        echo "容器已删除: $DOCKER_ID"
        unset DOCKER_ID
    else
        sudo docker rm "$1"
        echo "容器已删除: $1"
    fi
}

# 工作空间路径
alias cws='cd ~/Downloads/RoboOrchardLab/projects/sem/robotwin/ros2_ws/robo_orchard_deploy_ros2'
alias cwsr='cd ~/Downloads/RoboOrchardLab/projects/sem/robotwin/ros2_ws/'

# 编译相关
alias cbi='colcon build --packages-select robo_orchard_deploy --merge-install'
alias cb='colcon build --symlink-install'

